<template>
	<div>
		<div class="outer">
			<a-form :label-col="{span: 3}" :wrapper-col="{span: 14}">
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">默认短信接口</div>
				<a-radio-group v-model:value="formData.provider">
					<a-radio value="ali">阿里云短信</a-radio>
					<a-radio value="wangyi">网易短信</a-radio>
					<a-radio value="duanxinbao">短信宝</a-radio>
				</a-radio-group>

				<div class="w-100 b-b m-b-30 m-t-40 font-20 padding-b-5">阿里云短信</div>
				<a-form-item label="AppKey">
					<a-input v-model:value="formData.ali.AppKey" />
				</a-form-item>
				<a-form-item label="AppSecret">
					<a-input v-model:value="formData.ali.AppSecret" />
				</a-form-item>
				<a-form-item label="通用模板">
					<a-input v-model:value="formData.ali.templateids.common" />
				</a-form-item>
				<a-form-item label="注册模板">
					<a-input v-model:value="formData.ali.templateids.register" />
				</a-form-item>
				<a-form-item label="登录模板">
					<a-input v-model:value="formData.ali.templateids.login" />
				</a-form-item>
				<a-form-item label="找回密码模板">
					<a-input v-model:value="formData.ali.templateids.findPwd" />
				</a-form-item>
				<a-form-item label="修改手机号模板">
					<a-input v-model:value="formData.ali.templateids.editPhone" />
				</a-form-item>
				<a-form-item label="修改密码模板">
					<a-input v-model:value="formData.ali.templateids.editPwd" />
				</a-form-item>
				<a-form-item label="签名">
					<a-input v-model:value="formData.ali.signName" />
				</a-form-item>
				

				<div class="w-100" style="background-color: #f5f5f5;height: 5px;"></div>
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">网易短信</div>
				<a-form-item label="AppKey">
					<a-input v-model:value="formData.wangyi.AppKey" />
				</a-form-item>
				<a-form-item label="AppSecret">
					<a-input v-model:value="formData.wangyi.AppSecret" />
				</a-form-item>
				<a-form-item label="通用模板">
					<a-input v-model:value="formData.wangyi.templateids.common" />
				</a-form-item>
				<a-form-item label="注册模板">
					<a-input v-model:value="formData.wangyi.templateids.register" />
				</a-form-item>
				<a-form-item label="登录模板">
					<a-input v-model:value="formData.wangyi.templateids.login" />
				</a-form-item>
				<a-form-item label="找回密码模板">
					<a-input v-model:value="formData.wangyi.templateids.findPwd" />
				</a-form-item>
				<a-form-item label="修改手机号模板">
					<a-input v-model:value="formData.wangyi.templateids.editPhone" />
				</a-form-item>
				<a-form-item label="修改密码模板">
					<a-input v-model:value="formData.wangyi.templateids.editPwd" />
				</a-form-item>

				<div class="w-100" style="background-color: #f5f5f5;height: 5px;"></div>
				<div class="w-100 b-b m-b-30 m-t-20 font-20 padding-b-5">短信宝</div>
				<a-form-item label="username">
					<a-input v-model:value="formData.duanxinbao.username" />
				</a-form-item>
				<a-form-item label="API Key">
					<a-input v-model:value="formData.duanxinbao.appKey" />
				</a-form-item>
				<a-form-item label="请求网关">
					<a-input v-model:value="formData.duanxinbao.url" />
				</a-form-item>
				<a-form-item class="marginButton" :wrapper-col="{ span: 14, offset: 3 }">
					<a-button type="primary" @click="onSubmit">保存</a-button>
				</a-form-item>
			</a-form>
		</div>

	</div>
</template>

<script>
	import systemApi from '../../api/system.js'

	export default {
		data() {
			return {
				formData: {
					provider: 'ali', // 短信服务商，wangyi或ali
					wangyi: {
						AppKey: '',
						AppSecret: '',
						// 模板id
						templateids: {
							common: '', //通用
							register: '', // 注册
							login: '', // 登录
							findPwd: '', // 找回密码
							notice: '', // 通知
							editPhone: '', // 修改手机号
							editPwd: '', // 修改密码
							formlc_login: '', // 后台登录
						}
					},
					ali: {
						AppKey: '',
						AppSecret: '',
						signName: 'NETSS', // 签名
						// 模板CODE
						templateids: {
							common: '', //通用
							register: '', // 注册
							login: '', // 登录
							findPwd: '', // 找回密码
							notice: '', // 通知
							editPhone: '', // 修改手机号
							editPwd: '', // 修改密码
							formlc_login: '', // 后台登录
						}
					},
					duanxinbao: {
						username: '',
						appKey: '',
						url: 'https://api.smsbao.com/sms'
					},

					type: ['login', 'register', 'findPwd', 'real', 'common', 'editPhone', 'editPwd'], // 自定义发送验证码类型
					platform_type: ['formlc_login', 'formlc_action'], // 自定义后台发送验证码类型, formlc_action 常规操作
					platform_login_pre: ['form_login', 'form_action'], // 后台登录前缀
					login_prefix: 'api_login', // 前缀
					register_prefix: 'api_register', // 前缀
					findPwd_prefix: 'api_findPwd',
					real_prefix: 'api_real',
					sms_code_time: 300, // 短信验证码有效时间
				}
			}
		},
		mounted() {
			this.getSystemConfig()
		},
		methods: {
			getSystemConfig() {
				systemApi.getSystemConfig('sms').then(res => {
					if(res.status == 1){
						this.formData = res.result.sms
					}
				})
			},
			onSubmit() {
				systemApi.systemConfig(this.formData, 'sms').then(res => {
					if(res.status == 1){
						this.$message.success('修改成功')
					}
				})
			}
		}
	}
</script>
<style scoped>
</style>